package com.scy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.base.CaseFormat;
import com.scy.common.QueryPageBean;
import com.scy.entity.Medical;
import com.scy.mapper.MedicalMapper;
import com.scy.service.MedicalService;
import org.springframework.stereotype.Service;

@Service
public class MedicalServiceImpl extends ServiceImpl<MedicalMapper, Medical> implements MedicalService {
    @Override
    public IPage<Medical> getMedicalPage(QueryPageBean queryPageBean) {
        Page<Medical> page=new Page<>(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());

        QueryWrapper<Medical> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("logic_del",1);

        if(queryPageBean.getQueryTerm()!=null && queryPageBean.getQueryTerm().size()>0) {
            queryPageBean.getQueryTerm().forEach((k, v) -> {
                queryWrapper.like(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, k.toString()), "%"+v+"%");
            });
        }
        return baseMapper.selectPage(page,queryWrapper);
    }
}
